define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'detection/orders/index' + location.search,
                    // add_url: 'detection/orders/add',
                    edit_url: 'detection/orders/edit',
                    // del_url: 'detection/orders/del',
                    // multi_url: 'detection/orders/multi',
                    // import_url: 'detection/orders/import',
                    table: 'check_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'admin.nickname', title: __('Admin.nickname'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'detection.name', title: __('Detection.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'userid', title: __('Userid')},
                        {field: 'numbers', title: __('Numbers'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"-1":__('Status -1'),"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4')}, formatter: Table.api.formatter.status},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.status},
                        // {field: 'end_adminid', title: __('End_adminid')},
                        // {field: 'end_storeid', title: __('End_storeid')},
                        // {field: 'end_name', title: __('End_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'end_tags', title: __('End_tags'), operate: 'LIKE', formatter: Table.api.formatter.flag},
                        {field: 'end_price', title: __('End_price'), operate:'BETWEEN'},
                        {field: 'vehicle_image', title: __('Vehicle_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'plate_num', title: __('Plate_num'), operate: 'LIKE'},
                        {field: 'vehicle_type', title: __('Vehicle_type'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'sliptime', title: __('Sliptime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'car_model', title: __('Car_model'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'vin', title: __('Vin'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'engine_num', title: __('Engine_num'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'use_character', title: __('Use_character'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'car_years', title: __('Car_years'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'power_type', title: __('Power_type'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'face_image', title: __('Face_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'back_image', title: __('Back_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'username', title: __('Username'), operate: 'LIKE'},
                        {field: 'genderdata', title: __('Genderdata'), searchList: {"male":__('Genderdata male'),"female":__('Genderdata female')}, formatter: Table.api.formatter.normal},
                        {field: 'idcard', title: __('Idcard'), operate: 'LIKE'},
                        {field: 'checktime', title: __('Checktime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'is_diving', title: __('Is_diving'), searchList: {"0":__('Is_diving 0'),"1":__('Is_diving 1')}, formatter: Table.api.formatter.normal},
                        {field: 'city', title: __('City'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'longitude', title: __('Longitude'), operate:'BETWEEN'},
                        {field: 'latitude', title: __('Latitude'), operate:'BETWEEN'},
                        {field: 'gettime', title: __('Gettime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'getphone', title: __('Getphone'), operate: 'LIKE'},
                        {field: 'distance', title: __('Distance'), operate:'BETWEEN'},
                        {field: 'check_images', title: __('Check_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'attachfile', title: __('Attachfile'), operate: false, formatter: Table.api.formatter.file},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'begintime', title: __('Begintime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'overtime', title: __('Overtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'look_check', title: __('Look_check'), searchList: {"0":__('Look_check 0'),"1":__('Look_check 1'),"2":__('Look_check 2'),"3":__('Look_check 3')}, formatter: Table.api.formatter.normal},
                        {field: 'low_check', title: __('Low_check'), searchList: {"0":__('Low_check 0'),"1":__('Low_check 1'),"2":__('Low_check 2'),"3":__('Low_check 3')}, formatter: Table.api.formatter.normal},
                        {field: 'obd_check', title: __('Obd_check'), searchList: {"0":__('Obd_check 0'),"1":__('Obd_check 1'),"2":__('Obd_check 2'),"3":__('Obd_check 3')}, formatter: Table.api.formatter.normal},
                        {field: 'huan_check', title: __('Huan_check'), searchList: {"0":__('Huan_check 0'),"1":__('Huan_check 1'),"2":__('Huan_check 2'),"3":__('Huan_check 3')}, formatter: Table.api.formatter.normal},
                        {field: 'an_check', title: __('An_check'), searchList: {"0":__('An_check 0'),"1":__('An_check 1'),"2":__('An_check 2'),"3":__('An_check 3')}, formatter: Table.api.formatter.normal},
                        {field: 'san_check', title: __('San_check'), searchList: {"0":__('San_check 0'),"1":__('San_check 1'),"2":__('San_check 2'),"3":__('San_check 3')}, formatter: Table.api.formatter.normal},
                        {field: 'out_trade_no', title: __('Out_trade_no'), operate: 'LIKE'},
                        // {field: 'estimated_amount', title: __('Estimated_amount'), operate:'BETWEEN'},
                        // {field: 'all_money', title: __('All_money'), operate:'BETWEEN'},
                        {field: 'paytime', title: __('Paytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'pay_amount', title: __('Pay_amount'), operate:'BETWEEN'},
                        {field: 'pay_orderid', title: __('Pay_orderid'), operate: 'LIKE'},
                        {field: 'star_nums', title: __('Star_nums'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,buttons:[
                                {
                                    name: '开始检测',
                                    text: __(''),
                                    title: __('开始检测'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-steam',
                                    url: 'detection/orders/begin',
                                    confirm: '确认开始检测',
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                        // Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },
                            ], formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
